package com.zhentao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.mapper.ProductMapper;
import com.zhentao.pojo.CategoryLevel2;
import com.zhentao.pojo.Product;
import com.zhentao.service.CategoryLevel2Service;
import com.zhentao.mapper.CategoryLevel2Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author lenovo
* @description 针对表【category_level2(二级分类表)】的数据库操作Service实现
* @createDate 2025-08-29 09:27:34
*/
@Service
public class CategoryLevel2ServiceImpl extends ServiceImpl<CategoryLevel2Mapper, CategoryLevel2>
    implements CategoryLevel2Service{

    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private CategoryLevel2Mapper categoryLevel2Mapper;

    @Override
    public List<CategoryLevel2> getRecommendProduct() {
        // 获取商品平均评分前10的商品
        List<Product> products = productMapper.selectList(new QueryWrapper<Product>().orderByDesc("avg_score").last("Limit 10"));
        // 根据前十商品的二级分类id获取二级分类
        return categoryLevel2Mapper.selectBatchIds(products.stream().map(Product::getLevel2Id).toList());
    }
}




